package com.itheima.stringdemo;

public class Demo2 {

    public static void main(String[] args) {

        //生成验证码
        String code = getCode(4);
        System.out.println(code);
        System.out.println(getCode(6));
    }


    //生成指定位数的随机验证码，每位可能是大小写字母或数字
    //用string变量记住全部的字符
    public static String getCode(int n){
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        String code = "";
        for (int i = 0; i < n; i++) {
            int index = (int)(Math.random()*str.length());
            code += str.charAt(index);
        }
        return code;
    }


}
